<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>条件渲染</title>
    <script src="./js/babel.min.js"></script>
    <script src="./js/react.development.js"></script>
    <script src="./js/react-dom.development.js"></script>
    <style>
      #ad{
        width: 200px;
        height: 200px;
        background-color: #aef;
        position: fixed;
        right: 0;
        bottom: 0;
      }
    </style>
  </head>
  <body>
    <div id="root"></div>
    <script type="text/babel">
      //声明变量
      let isVip = false;// 是否是会员

      // var vdom = null;
      //1. 方式
      // if(!isVip){
      //   vdom = <div id="ad">我是广告</div>;
      // }

      //2. 逻辑与   ✅
      // let vdom = <div>
      //     <h2>欢迎来到王者荣耀</h2>
      //     {!isVip && <div id="ad">新皮肤登场 - 热卖中</div>}
      //   </div>;
        
      //3. 三元运算符  ✅
      // let vdom = <div>
      //     <h2>欢迎来到王者荣耀</h2>
      //     {isVip ? null : <div id="ad">新皮肤登场 - 热卖中</div>}
      //   </div>;

      //4. 封装函数
      function getAd(){
        if(isVip){
          return null;
        }else{
          return <div id="ad">新皮肤登场 - 热卖中</div>;
        }
      }

      let vdom = <div>
          <h2>欢迎来到王者荣耀</h2>
          {getAd()}
        </div>;

      //渲染  就是将虚拟 DOM 转为真实 DOM 插入到文档的过程
      ReactDOM.render(vdom, document.querySelector('#root'));


      // let res = null && 2;

      // console.log(res);
    </script>
  </body>
</html>
